/* eslint-disable no-return-assign */
/* eslint-disable no-return-assign */
<template>
  <div id="updateOwnInfo">
    <el-tabs v-model="activeName" class="tabPlane">
      <el-tab-pane label="个人信息" name='1'>
        <div class="goback" @click="routerGoBack" style="cursor: pointer;padding:0px 23px;margin-bottom:15px;">
          <i class="el-icon-arrow-left"></i>返回
        </div>
        <div class="contentClass onlyShowContent">
          <el-form :model="studentBaseInfoVo" status-icon ref="studentBaseInfoVo" :rules="basicInfoFormRules" class="updateForm" label-position="top" autocomplete="off">
            <el-row :gutter="100">
              <el-col :span='24'>
                <el-form-item label="" prop="picUrl" class="fl">
                  <div class="clearFix p10">
                    <el-upload disabled action="" class="avatar-uploader" :show-file-list="false">
                      <img :src="generateImgUrl(studentBaseInfoVo.picUrl)" class="avatar">
                    </el-upload>
                    <div class="pic-title">入学照片</div>
                  </div>

                </el-form-item>
                <el-form-item label="" prop="lifeHeadUrl" class="fl">
                  <div class="clearFix p10">
                    <el-upload class="avatar-uploader" :action="prodUrl(`${isDev ? '/root' : ''}/fastdfs-util/api/fastdfs/upload/image/sample`)" :show-file-list="false" :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload">
                      <img :src="generateImgUrl(studentBaseInfoVo.lifeHeadUrl)" class="avatar">
                    </el-upload>
                    <div class="pic-title">生活照片</div>
                  </div>

                </el-form-item>
                <p style="font-size:12px;font-weight:300;margin-top:150px;">点击图片，上传照片，请上传小于5M的照片，仅可修改“照片”</p>
              </el-col>
            </el-row>
            <!--<el-col :span="24">-->
            <!--<el-form-item style="text-align:center;margin-top:30px;">-->
            <!--<el-button @click="updateInfo('studentBaseInfoVo')" style="width:100px;">测试</el-button>-->
            <!--</el-form-item>-->
            <!--</el-col>-->
            <el-row :gutter="100">
              <el-col :span="24">
                <h2 class="titleH">基本信息</h2>
              </el-col>

              <el-col :span="8">
                <el-form-item label="学号" prop="sn">
                  <el-input size="small" type="text" v-model="studentBaseInfoVo.sn" autocomplete="off" :disabled="true"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="姓名" prop="name">
                  <el-input size="small" type="text" v-model="studentBaseInfoVo.name" autocomplete="off" @change="getName"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="曾用名" prop="formerName ">
                  <el-input size="small" type="text" v-model="studentBaseInfoVo.formerName" autocomplete="off"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="性别" prop="genderId">
                  <el-select size='small' v-model="studentBaseInfoVo.genderId" placeholder="请选择" @change="handleChangeValidate('genderId')">
                    <el-option v-for="item in allOption['性别']" :key="item.id" :label="item.name" :value="item.id">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="民族" prop="nationId">
                  <el-select size='small' v-model="studentBaseInfoVo.nationId" placeholder="请选择" @change="handleChangeValidate('nationId')">
                    <el-option v-for="item in allOption['民族']" :key="item.id" :label="item.name" :value="item.id">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="国籍" prop="nationalityId">
                  <el-select size='small' v-model="studentBaseInfoVo.nationalityId" placeholder="请选择" @change="handleChangeValidate('nationalityId',studentBaseInfoVo.nationalityId)">
                    <el-option v-for="item in allOption['国籍']" :key="item.id" :label="item.name" :value="item.id">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>

              <el-col :span="8">
                <el-form-item label="籍贯" prop="nativePlaceCode">
                  <el-cascader size='small' v-model="studentBaseInfoVo.nativePlaceCode" separator=' ' :options="cascadeOptions" @change="handleChangeValidate('nativePlaceCode')">
                  </el-cascader>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="身份证号" prop="idNumber">
                  <el-input size="small" type="text" v-model="studentBaseInfoVo.idNumber" autocomplete="off" @blur="updateBirthDate"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="出生日期" prop="birthDate">
                  <el-input v-model="studentBaseInfoVo.birthDate" placeholder="" size="small" :disabled="true" suffix-icon="el-icon-date"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="政治面貌" prop="politicsStatusId">
                  <el-select size='small' v-model="studentBaseInfoVo.politicsStatusId" placeholder="请选择" @change="handleChangeValidate('politicsStatusId')">
                    <el-option v-for="item in allOption['政治面貌']" :key="item.id" :label="item.name" :value="item.id">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="血型" prop="bloodTypeId">
                  <el-select size='small' v-model="studentBaseInfoVo.bloodTypeId" placeholder="请选择" @change="handleChangeValidate('bloodTypeId')">
                    <el-option v-for="item in allOption['血型']" :key="item.id" :label="item.name" :value="item.id">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="宗教信仰" prop="religionId">
                  <el-select size='small' v-model="studentBaseInfoVo.religionId" placeholder="请选择" @change="handleChangeValidate('religionId')">
                    <el-option v-for="item in allOption['宗教信仰']" :key="item.id" :label="item.name" :value="item.id">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="现在户口所在地" prop="currentDomicilePlaceCode">
                  <el-cascader size='small' v-model="studentBaseInfoVo.currentDomicilePlaceCode" separator=' ' :options="cascadeOptions" @change="handleChangeValidate('currentDomicilePlaceCode')">
                  </el-cascader>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="火车乘车区间" prop="destinationPlace">
                  <span :disabled="true" style="vertical-align: middle;width:47%;height:30px;display:inline-block;text-align:center;background-color: #d2d2d2;cursor: default;color: #999;border-radius: 4px;border: 1px solid #dcdfe6;" size="small">{{studentBaseInfoVo.departurePlace}}</span>-
                  <el-autocomplete value-key="name" v-model="studentBaseInfoVo.destinationPlace" :trigger-on-focus="false" placeholder="目的地" size="small" style="width:48%" :fetch-suggestions="querySearchCity" @select="handleSelectCity" @change="changeSearchCity"></el-autocomplete>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="婚姻状况" prop="maritalStatusId">
                  <el-select size='small' v-model="studentBaseInfoVo.maritalStatusId" placeholder="请选择" @change="handleChangeValidate('maritalStatusId')">
                    <el-option v-for="item in allOption['婚姻状况']" :key="item.id" :label="item.name" :value="item.id">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>

              <el-col :span="8">
                <el-form-item label="与学校联名银行卡账户" prop="openingBank">
                  <el-input size="small" type="text" v-model="studentBaseInfoVo.openingBank" autocomplete="off"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="银行卡号" prop="bankCard">
                  <el-input size="small" type="text" v-model="studentBaseInfoVo.bankCard" autocomplete="off"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="特长爱好" prop="hobby">
                  <el-input size="small" type="text" v-model="studentBaseInfoVo.hobby" autocomplete="off"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="健康状况" prop="healthStateId">
                  <el-select size='small' v-model="studentBaseInfoVo.healthStateId" placeholder="请选择" @change="handleChangeValidate('healthStateId')">
                    <el-option v-for="item in allOption['健康状况']" :key="item.id" :label="item.name" :value="item.id">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="校园一卡通卡号" prop="metroCard">
                  <el-input size="small" type="text" v-model="studentBaseInfoVo.metroCard" autocomplete="off"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="辅导员姓名" prop="instructorName">
                  <el-input size="small" type="text" v-model="studentBaseInfoVo.instructorName" autocomplete="off" :disabled="true"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="班主任姓名" prop="classTeacher">
                  <el-input size="small" type="text" v-model="studentBaseInfoVo.classTeacher" autocomplete="off" :disabled="true"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="身高（cm）" prop="stature">
                  <el-input size="small" type="number" v-model="studentBaseInfoVo.stature" autocomplete="off"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="体重（Kg）" prop="weight">
                  <el-input size="small" type="number" v-model="studentBaseInfoVo.weight" autocomplete="off"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="100">
              <el-col :span="24">
                <h2 class="titleH">学籍信息</h2>
              </el-col>
              <el-col :span="8">
                <el-form-item label="所属学院" prop="collegeName">
                  <el-input size="small" type="text" v-model="studentBaseInfoVo.collegeName" autocomplete="off" :disabled="true"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="所属专业" prop="majorName">
                  <el-input size="small" type="text" v-model="studentBaseInfoVo.majorName" autocomplete="off" :disabled="true"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="所属年级" prop="grade">
                  <el-input size="small" type="text" v-model="studentBaseInfoVo.grade" autocomplete="off" :disabled="true"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="所属班级" prop="className">
                  <el-input size="small" type="text" v-model="studentBaseInfoVo.className" autocomplete="off" :disabled="true"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="生源类型" prop="sourceType">
                  <el-input size="small" type="text" v-model="studentBaseInfoVo.sourceType" autocomplete="off" :disabled="true"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="学籍状态" prop="educationStatus">
                  <el-input size="small" type="text" v-model="studentBaseInfoVo.educationStatus" autocomplete="off" :disabled="true"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="学生类型" prop="educationId">
                  <el-select size='small' v-model="studentBaseInfoVo.educationId" placeholder="" @change="handleChangeValidate('educationId')" :disabled="true">
                    <el-option v-for="item in allOption['学生类型']" :key="item.id" :label="item.name" :value="item.id">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="是否在籍" prop="absentee">
                  <div class="disableInput">{{studentBaseInfoVo.absentee | isTransform}}</div>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="是否在校" prop="atSchool">
                  <div class="disableInput">{{studentBaseInfoVo.atSchool | isTransform }}</div>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="毕业时间（预计）" prop="graduateDate">
                  <el-date-picker size="small" v-model="studentBaseInfoVo.graduateDate" type="month" placeholder="选择日期" :picker-options="pickerOptions"></el-date-picker>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="100">
              <el-col :span="24">
                <h2 class="titleH">入学信息</h2>
              </el-col>
              <el-col :span="8">
                <el-form-item label="入学年月" prop="enterDate">
                  <el-date-picker size="small" v-model="studentBaseInfoVo.enterDate" type="date" placeholder="选择日期"></el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="入学前户口所在地" prop="domicilePlaceCode">
                  <el-cascader size='small' v-model="studentBaseInfoVo.domicilePlaceCode" separator=' ' :options="cascadeOptions" @change="handleChangeValidate('domicilePlaceCode')">
                  </el-cascader>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="生源地" prop="sourcePlaceCode">
                  <el-select size="small" v-model="studentBaseInfoVo.sourcePlaceCode" placeholder="请选择" @change="handleChangeValidate('sourcePlaceCode')">
                    <el-option v-for="item in sourcePlaceOptions" :key="item.code" :label="item.name" :value="item.code">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="入学前就读中学" prop="highSchool">
                  <el-input size="small" type="text" v-model="studentBaseInfoVo.highSchool" autocomplete="off"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="高考分数" prop="satScores">
                  <el-input size="small" v-model="studentBaseInfoVo.satScores" autocomplete="off" :disabled="true"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="邮寄录取通知书家庭地址" prop="mailHomeAddress">
                  <el-input size="small" v-model="studentBaseInfoVo.mailHomeAddress" autocomplete="off" :disabled="true"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="邮寄录取通知书收件人姓名" prop="addresseeName">
                  <el-input size="small" v-model="studentBaseInfoVo.addresseeName" autocomplete="off" :disabled="true"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="邮寄录取通知书收件人电话" prop="addresseePhone">
                  <el-input size="small" v-model="studentBaseInfoVo.addresseePhone" autocomplete="off" :disabled="true"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <h2 class="titleH">通讯信息</h2>
              </el-col>
              <el-col :span="8">
                <el-form-item label="宿舍分布区" prop="dormitoryArea">
                  <el-input size="small" type="text" v-model="studentBaseInfoVo.dormitoryArea" autocomplete="off" :disabled="true"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="寝室号" prop="dorm">
                  <el-input size="small" type="number" v-model="studentBaseInfoVo.dorm" autocomplete="off" :disabled="true"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="联系电话" prop="phone">
                  <el-input size="small" v-model="studentBaseInfoVo.phone" autocomplete="off"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="备用电话" prop="standbyPhone">
                  <el-input size="small" type="text" v-model="studentBaseInfoVo.standbyPhone" autocomplete="off"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="微信号" prop="wechat">
                  <el-input size="small" type="text" v-model="studentBaseInfoVo.wechat" autocomplete="off"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="QQ号码" prop="qq">
                  <el-input size="small" type="text" v-model="studentBaseInfoVo.qq" autocomplete="off"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="邮箱" prop="email">
                  <el-input size="small" type="text" v-model="studentBaseInfoVo.email" autocomplete="off"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="家庭电话" prop="familyPhone">
                  <el-input size="small" type="text" v-model="studentBaseInfoVo.familyPhone" autocomplete="off"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="家庭电子邮箱" prop="familyEmail">
                  <el-input size="small" type="text" v-model="studentBaseInfoVo.familyEmail" autocomplete="off"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="家庭所在地区" prop="familyPlaceCode">
                  <el-cascader ref="cascaderAddr" size='small' v-model="studentBaseInfoVo.familyPlaceCode" separator=' ' :options="cascadeOptions" @change="onFamilyPlacechange('familyPlaceCode')">
                  </el-cascader>

                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="家庭详细地址" prop="familyDetailAddress">
                  <el-input size="small" type="text" v-model="studentBaseInfoVo.familyDetailAddress" autocomplete="off"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="家庭完整地址" prop="completeAddress">
                  <el-input size="small" type="text" v-model="completeAddress" autocomplete="off" :disabled="true"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="100">
              <el-col :span="24">
                <h2 class="titleH">家庭信息</h2>
              </el-col>
              <el-col :span="24">
                <p class="clearFix">父母类
                </p>
                <el-table :data="studentParents" style="width: 100%">
                  <el-table-column prop="date" label="序号" width="90">
                    <template slot-scope="scope">
                      {{scope.$index + 1}}
                    </template>
                  </el-table-column>
                  <el-table-column prop="relation" label="关系">
                    <template slot-scope="scope">
                      <span v-if="!scope.row.isEdit">{{scope.row.relation}}</span>
                      <el-select v-if="scope.row.isEdit" size='mini' v-model="scope.row.relationId" placeholder="请选择" @change="handleChange(scope.row,'父母')">
                        <el-option v-for="item in allOption['父母']" :key="item.id" :label="item.name" :value="item.id">
                        </el-option>
                      </el-select>
                    </template>
                  </el-table-column>
                  <el-table-column prop="name" label="姓名">
                    <template slot-scope="scope">
                      <span v-if="!scope.row.isEdit">{{scope.row.name}}</span>
                      <el-input v-if="scope.row.isEdit" size="mini" v-model="scope.row.name" placeholder="请输入姓名"></el-input>
                    </template>
                  </el-table-column>
                  <el-table-column prop="phone" label="联系电话">
                    <template slot-scope="scope">
                      <span v-if="!scope.row.isEdit">{{scope.row.phone}}</span>
                      <el-input v-if="scope.row.isEdit" size="mini" v-model="scope.row.phone" placeholder="请输入联系电话"></el-input>
                    </template>
                  </el-table-column>
                  <el-table-column prop="birthDate" label="出生日期">
                    <template slot-scope="scope">
                      <span v-if="!scope.row.isEdit"> {{scope.row.birthDate | moment('YYYY-MM-DD') }}</span>
                      <el-date-picker v-if="scope.row.isEdit" size="mini" v-model="scope.row.birthDate" type="date" placeholder="选择日期"></el-date-picker>
                    </template>
                  </el-table-column>
                  <el-table-column prop="education" label="学历">
                    <template slot-scope="scope">
                      <span v-if="!scope.row.isEdit">{{scope.row.education}}</span>
                      <el-select v-if="scope.row.isEdit" size='mini' v-model="scope.row.educationId" placeholder="请选择" @change="handleChange(scope.row,'学历')">
                        <el-option v-for="item in allOption['学历']" :key="item.id" :label="item.name" :value="item.id">
                        </el-option>
                      </el-select>
                    </template>
                  </el-table-column>
                  <el-table-column prop="politicsStatus" label="政治面貌">
                    <template slot-scope="scope">
                      <span v-if="!scope.row.isEdit">{{scope.row.politicsStatus}}</span>
                      <el-select v-if="scope.row.isEdit" size='mini' v-model="scope.row.politicsStatusId" placeholder="请选择" @change="handleChange(scope.row,'政治面貌')">
                        <el-option v-for="item in allOption['政治面貌']" :key="item.id" :label="item.name" :value="item.id">
                        </el-option>
                      </el-select>
                    </template>
                  </el-table-column>
                  <el-table-column prop="workUnit" label="工作单位">
                    <template slot-scope="scope">
                      <span v-if="!scope.row.isEdit">{{scope.row.workUnit}}</span>
                      <el-input v-if="scope.row.isEdit" size="mini" v-model="scope.row.workUnit" placeholder="请输入工作单位"></el-input>
                    </template>
                  </el-table-column>
                  <el-table-column prop="duty" label="职务">
                    <template slot-scope="scope">
                      <span v-if="!scope.row.isEdit">{{scope.row.duty}}</span>
                      <el-input v-if="scope.row.isEdit" size="mini" v-model="scope.row.duty" placeholder="请输入职务"></el-input>
                    </template>
                  </el-table-column>
                  <el-table-column label="操作">
                    <template slot-scope="scope">
                      <div v-if="!scope.row.isEdit">
                        <el-button type="text" @click="updateRelation(scope.row,scope.$index,0)">修改</el-button>
                      </div>
                      <div v-if="scope.row.isEdit">
                        <el-button type="text" @click="saveRelation(scope.row,0)">保存</el-button>
                        <el-button type="text" @click="cancelRelation(scope,0)">取消</el-button>
                      </div>
                    </template>
                  </el-table-column>
                </el-table>
              </el-col>
              <el-col :span="24">
                <p class="clearFix">
                  直系亲属类
                  <el-button class="fr" type="primary" size="mini" @click="addRelation(1)">新建</el-button>
                </p>
                <el-table :data="studentrelatives" style="width: 100%">
                  <el-table-column prop="date" label="序号" width="90">
                    <template slot-scope="scope">
                      {{scope.$index + 1}}
                    </template>
                  </el-table-column>
                  <el-table-column prop="relation" label="关系">
                    <template slot-scope="scope">
                      <span v-if="!scope.row.isEdit">{{scope.row.relation}}</span>
                      <el-select v-if="scope.row.isEdit" size='mini' v-model="scope.row.relationId" placeholder="请选择" @change="handleChange(scope.row,'直系亲属')">
                        <el-option v-for="item in allOption['直系亲属']" :key="item.id" :label="item.name" :value="item.id">
                        </el-option>
                      </el-select>
                    </template>
                  </el-table-column>
                  <el-table-column prop="name" label="姓名">
                    <template slot-scope="scope">
                      <span v-if="!scope.row.isEdit">{{scope.row.name}}</span>
                      <el-input v-if="scope.row.isEdit" size="mini" v-model="scope.row.name" placeholder="请输入姓名"></el-input>
                    </template>
                  </el-table-column>
                  <el-table-column prop="phone" label="联系电话">
                    <template slot-scope="scope">
                      <span v-if="!scope.row.isEdit">{{scope.row.phone}}</span>
                      <el-input v-if="scope.row.isEdit" size="mini" v-model="scope.row.phone" placeholder="请输入联系电话"></el-input>
                    </template>
                  </el-table-column>
                  <el-table-column prop="birthDate" label="出生日期">
                    <template slot-scope="scope">
                      <span v-if="!scope.row.isEdit"> {{scope.row.birthDate | moment('YYYY-MM-DD') }}</span>
                      <el-date-picker v-if="scope.row.isEdit" size="mini" v-model="scope.row.birthDate" type="date" placeholder="选择日期"></el-date-picker>
                    </template>
                  </el-table-column>
                  <el-table-column prop="education" label="学历">
                    <template slot-scope="scope">
                      <span v-if="!scope.row.isEdit">{{scope.row.education}}</span>
                      <el-select v-if="scope.row.isEdit" size='mini' v-model="scope.row.educationId" placeholder="请选择" @change="handleChange(scope.row,'学历')">
                        <el-option v-for="item in allOption['学历']" :key="item.id" :label="item.name" :value="item.id">
                        </el-option>
                      </el-select>
                    </template>
                  </el-table-column>
                  <el-table-column prop="politicsStatus" label="政治面貌">
                    <template slot-scope="scope">
                      <span v-if="!scope.row.isEdit">{{scope.row.politicsStatus}}</span>
                      <el-select v-if="scope.row.isEdit" size='mini' v-model="scope.row.politicsStatusId" placeholder="请选择" @change="handleChange(scope.row,'政治面貌')">
                        <el-option v-for="item in allOption['政治面貌']" :key="item.id" :label="item.name" :value="item.id">
                        </el-option>
                      </el-select>
                    </template>
                  </el-table-column>
                  <el-table-column prop="workUnit" label="工作单位">
                    <template slot-scope="scope">
                      <span v-if="!scope.row.isEdit">{{scope.row.workUnit}}</span>
                      <el-input v-if="scope.row.isEdit" size="mini" v-model="scope.row.workUnit" placeholder="请输入工作单位"></el-input>
                    </template>
                  </el-table-column>
                  <el-table-column prop="duty" label="职务">
                    <template slot-scope="scope">
                      <span v-if="!scope.row.isEdit">{{scope.row.duty}}</span>
                      <el-input v-if="scope.row.isEdit" size="mini" v-model="scope.row.duty" placeholder="请输入职务"></el-input>
                    </template>
                  </el-table-column>
                  <el-table-column label="操作">
                    <template slot-scope="scope">
                      <div v-if="!scope.row.isEdit">
                        <el-button type="text" @click="updateRelation(scope.row,scope.$index,1)">修改</el-button>
                        <el-button class="red" type="text" @click="deleteRelation(scope,1)">删除</el-button>
                      </div>
                      <div v-if="scope.row.isEdit">
                        <el-button type="text" @click="saveRelation(scope.row,1)">保存</el-button>
                        <el-button type="text" @click="cancelRelation(scope,1)">取消</el-button>
                      </div>
                    </template>
                  </el-table-column>
                </el-table>
              </el-col>
              <el-col :span="24">
                <p class="clearFix">
                  其他社会重要联系人类
                  <el-button class="fr" type="primary" size="mini" @click="addRelation(2)">新建</el-button>
                </p>
                <el-table :data="studentFriends" style="width: 100%">
                  <el-table-column prop="date" label="序号" width="90">
                    <template slot-scope="scope">
                      {{scope.$index + 1}}
                    </template>
                  </el-table-column>
                  <el-table-column prop="relation" label="关系">
                    <template slot-scope="scope">
                      <span v-if="!scope.row.isEdit">{{scope.row.relation}}</span>
                      <el-select v-if="scope.row.isEdit" size='mini' v-model="scope.row.relationId" placeholder="请选择" @change="handleChange(scope.row,'社会联系人')">
                        <el-option v-for="item in allOption['社会联系人']" :key="item.id" :label="item.name" :value="item.id">
                        </el-option>
                      </el-select>
                    </template>
                  </el-table-column>
                  <el-table-column prop="name" label="姓名">
                    <template slot-scope="scope">
                      <span v-if="!scope.row.isEdit">{{scope.row.name}}</span>
                      <el-input v-if="scope.row.isEdit" size="mini" v-model="scope.row.name" placeholder="请输入姓名"></el-input>
                    </template>
                  </el-table-column>
                  <el-table-column prop="phone" label="联系电话">
                    <template slot-scope="scope">
                      <span v-if="!scope.row.isEdit">{{scope.row.phone}}</span>
                      <el-input v-if="scope.row.isEdit" size="mini" v-model="scope.row.phone" placeholder="请输入联系电话"></el-input>
                    </template>
                  </el-table-column>
                  <el-table-column prop="birthDate" label="出生日期">
                    <template slot-scope="scope">
                      <span v-if="!scope.row.isEdit"> {{scope.row.birthDate | moment('YYYY-MM-DD') }}</span>
                      <el-date-picker v-if="scope.row.isEdit" size="mini" v-model="scope.row.birthDate" type="date" placeholder="选择日期"></el-date-picker>
                    </template>
                  </el-table-column>
                  <el-table-column prop="education" label="学历">
                    <template slot-scope="scope">
                      <span v-if="!scope.row.isEdit">{{scope.row.education}}</span>
                      <el-select v-if="scope.row.isEdit" size='mini' v-model="scope.row.educationId" placeholder="请选择" @change="handleChange(scope.row,'学历')">
                        <el-option v-for="item in allOption['学历']" :key="item.id" :label="item.name" :value="item.id">
                        </el-option>
                      </el-select>
                    </template>
                  </el-table-column>
                  <el-table-column prop="politicsStatus" label="政治面貌">
                    <template slot-scope="scope">
                      <span v-if="!scope.row.isEdit">{{scope.row.politicsStatus}}</span>
                      <el-select v-if="scope.row.isEdit" size='mini' v-model="scope.row.politicsStatusId" placeholder="请选择" @change="handleChange(scope.row,'政治面貌')">
                        <el-option v-for="item in allOption['政治面貌']" :key="item.id" :label="item.name" :value="item.id">
                        </el-option>
                      </el-select>
                    </template>
                  </el-table-column>
                  <el-table-column prop="workUnit" label="工作单位">
                    <template slot-scope="scope">
                      <span v-if="!scope.row.isEdit">{{scope.row.workUnit}}</span>
                      <el-input v-if="scope.row.isEdit" size="mini" v-model="scope.row.workUnit" placeholder="请输入工作单位"></el-input>
                    </template>
                  </el-table-column>
                  <el-table-column prop="duty" label="职务">
                    <template slot-scope="scope">
                      <span v-if="!scope.row.isEdit">{{scope.row.duty}}</span>
                      <el-input v-if="scope.row.isEdit" size="mini" v-model="scope.row.duty" placeholder="请输入职务"></el-input>
                    </template>
                  </el-table-column>
                  <el-table-column label="操作">
                    <template slot-scope="scope">
                      <div v-if="!scope.row.isEdit">
                        <el-button type="text" @click="updateRelation(scope.row,scope.$index,2)">修改</el-button>
                        <el-button class="red" type="text" @click="deleteRelation(scope,2)">删除</el-button>
                      </div>
                      <div v-if="scope.row.isEdit">
                        <el-button type="text" @click="saveRelation(scope.row,2)">保存</el-button>
                        <el-button type="text" @click="cancelRelation(scope,2)">取消</el-button>
                      </div>
                    </template>
                  </el-table-column>
                </el-table>
              </el-col>
            </el-row>
            <el-row :gutter="100">
              <el-col :span="24">
                <p style="color:gray;"> 家庭信息：请至少录入一名其他社会重要联系人类信息</p>
              </el-col>
            </el-row>
            <el-row :gutter="100">
              <el-col :span="24">
                <el-form-item style="text-align:center;margin-top:30px;">
                  <el-button @click="resetForm('studentBaseInfoVo')" style="width:100px;">取消</el-button>
                  <el-button type="primary" @click="submitForm('studentBaseInfoVo')" style="width:100px;">提交</el-button>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
      </el-tab-pane>
    </el-tabs>
    <el-dialog title="个人信息" :visible.sync="dialogVisible" width="30%">
      <el-alert title="是否确认提交？" type="warning" show-icon :closable="false">
      </el-alert>
      <div style="color:gray;margin:10px auto;">备注：提交后需辅导员进行审核。</div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false" size="medium">取消</el-button>
        <el-button type="primary" @click="submitData" :disabled='disable' size="medium">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import * as R from 'ramda'

import { student, common, dataDictionary } from '@api/index'
import defaultPic from '@/assets/images/defaultPic.png'
import { _checkIdNum, _checkbankNum, _checkMobilePhone, _checkQQ, _checkEmail, _checFamilyPhone, prodUrl, cover, checkCode } from '@/tools/utils'
export default {
  name: 'updateOwnInfo',
  data () {
    const trainValid = (rule, value, callback) => {
      if (value === '' || value === null || value === undefined) {
        callback()
      } else {
        if (this.recordDestinationPlace && this.recordDestinationPlace === value) {
          callback()
        } else {
          callback(new Error('请输入正确站点名称'))
        }
      }
    }
    return {
      disable: false,
      recordDestinationPlace: null,
      drivingRangeOptions: [],
      pickerOptions: {
        disabledDate (time) {
          return time.getMonth() !== 5
        }
      },
      dialogVisible: false, // 提交提示框
      activeName: '1',
      basicInfoFormRules: {
        lifeHeadUrl: [{required: true, message: '请上传头像', trigger: 'blur'}],
        name: [{ required: true, message: '请输入姓名', trigger: 'blur' }, { min: 2, max: 30, message: '长度在 2 到 30 个字符', trigger: 'blur' }],
        genderId: [{ required: true, message: '请选择性别', trigger: 'blur' }],
        nationId: [{ required: true, message: '请选择民族', trigger: 'blur' }],
        nationalityId: [{ required: true, message: '请选择国籍', trigger: 'blur' }],
        nativePlaceCode: [{ required: true, message: '请选择籍贯', trigger: 'blur' }],
        idNumber: [{required: true, message: '请填写身份证号码', trigger: 'blur'}],
        politicsStatusId: [{ required: true, message: '请选择政治面貌', trigger: 'blur' }],
        bloodTypeId: [{ required: true, message: '请选择血型', trigger: 'blur' }],
        religionId: [{ required: true, message: '请选择宗教信仰', trigger: 'blur' }],
        currentDomicilePlaceCode: [{ required: true, message: '请选择现在户口所在地', trigger: 'blur' }],
        destinationPlace: [
          { required: true, message: '请输入正确站点名称', trigger: ['blur'] },
          {
            validator: trainValid,
            trigger: 'blur'
          }
        ],
        maritalStatusId: [{ required: true, message: '请选择婚姻状况', trigger: 'blur' }],
        openingBank: [{ required: true, message: '请输入与学校联名银行卡账户', trigger: 'blur' }, { min: 2, max: 30, message: '长度在 2 到 30 个字符', trigger: 'blur' }],
        bankCard: [{ required: true, validator: _checkbankNum, trigger: 'blur' }],
        healthStateId: [{ required: true, message: '请选择健康状况', trigger: 'blur' }],
        stature: [{required: true, message: '请填写身高', trigger: 'blur'}, {
          validator (rule, value, callback) {
            if (value === '' || value === null || value === undefined) {
              callback()
            } else {
              if (/^-?\d+(\.\d{1,2})?$/.test(value)) {
                let temp = parseFloat(value).toFixed(2)
                if (temp >= 300) {
                  callback(new Error('身高小于300cm'))
                } else {
                  callback()
                }
              } else {
                callback(new Error('小数位不能超过两位'))
              }
            }
          },
          trigger: 'blur'
        }],
        weight: [{required: true, message: '请填写体重', trigger: 'blur'}, {
          validator (rule, value, callback) {
            if (value === '' || value === null || value === undefined) {
              callback()
            } else {
              if (/^-?\d+(\.\d{1,2})?$/.test(value)) {
                let temp = parseFloat(value).toFixed(2)
                if (temp >= 500) {
                  callback(new Error('体重小于500Kg'))
                } else {
                  callback()
                }
              } else {
                callback(new Error('小数位不能超过两位'))
              }
            }
          },
          trigger: 'blur'
        }],
        metroCard: [{required: true, message: '请填写校园一卡通卡号', trigger: 'blur'}],
        graduateDate: [{ required: true, message: '请选择毕业时间', trigger: 'blur' }],
        // educationId: [{ required: true, message: '请选择学生类型', trigger: 'blur' }],
        enterDate: [{ required: true, message: '请选择入学年月', trigger: 'blur' }],
        domicilePlaceCode: [{ required: true, message: '请选择入学年月', trigger: 'blur' }],
        sourcePlaceCode: [{ required: true, message: '请选择生源地', trigger: 'blur' }],
        highSchool: [{ required: true, message: '请输入入学前就读中学', trigger: 'blur' }, { min: 2, max: 30, message: '长度在 2 到 30 个字符', trigger: 'blur' }],
        phone: [{ validator: _checkMobilePhone, trigger: 'blur' }, {required: true, message: '请填写联系电话', trigger: 'blur'}],
        standbyPhone: [{ validator: _checkMobilePhone, trigger: 'blur' }, {required: true, message: '请填写备用电话', trigger: 'blur'}],
        wechat: [{ required: true, message: '请输入微信号', trigger: 'blur' }, { min: 1, max: 30, message: '长度在 2 到 30 个字符', trigger: 'blur' }],
        qq: [{required: true, message: '请填写QQ号码', trigger: 'blur'}, {validator: _checkQQ, trigger: 'blur'}],
        email: [{required: true, message: '请填写邮箱', trigger: 'blur'}, {validator: _checkEmail, trigger: 'blur'}],
        familyPhone: [{ required: true, validator: _checFamilyPhone, trigger: 'blur' }],
        familyEmail: [{required: true, message: '请填写家庭电子邮箱', trigger: 'blur'}, {validator: _checkEmail, trigger: 'blur'}],
        familyPlaceCode: [{ required: true, message: '请选择家庭所在地区', trigger: 'blur' }],
        familyDetailAddress: [{required: true, message: '请填写家庭详细地址', trigger: 'blur'}]
      },
      studentBaseInfoVo: {},
      cascadeOptions: [], // 地址级联
      // 大部分下拉框options
      allOption: {},
      // 生源地下拉框options
      sourcePlaceOptions: [],
      studentBasic: {}, // 基础信息
      studentContact: {
      }, // 联系信息
      studentEducation: {

      }, // 教育信息

      studentParents: [],
      studentrelatives: [],
      studentFriends: []
    }
  },
  mounted () {
    if (this.$route.query.type === 2) {
      this.getCommitHistoryInfo()
      this.getAllProvinces()
      this.getAllSourcePlace()
      this.getAll()
    } else {
      this.getStudentBaseInfo()
      this.getAllProvinces()
      this.getAllSourcePlace()
      this.getAll()
    }
    // this.initPage()
    // this.getCommitHistoryInfo()
  },
  computed: {
    completeAddress () {
      return (this.studentBaseInfoVo.familyPlace ? this.studentBaseInfoVo.familyPlace + ' ' : '') + (this.studentBaseInfoVo.familyDetailAddress ? this.studentBaseInfoVo.familyDetailAddress : '')
    },
    trainFlag () {
      return this.recordDestinationPlace
    }
  },
  methods: {
    getName () {
      console.log(this.studentBaseInfoVo.name)
    },
    // 获取目的地
    querySearchCity (queryString, cb) {
      if (queryString) {
        this.drivingRangeOptions = []
        common()._selectCityByName(
          {name: queryString}
        ).then(res => {
          if (res.status) {
            if (res.data.length !== 0) {
              let newArray = []
              res.data.forEach(item => {
                let newItem = Object.assign(item, {
                  name: `${item.name}-${item.province_name}`
                })
                newArray.push(newItem)
              })
              this.drivingRangeOptions.push(...newArray)
              // // 调用 callback 返回建议列表的数据
              cb(this.drivingRangeOptions)
            } else {
              cb(this.drivingRangeOptions)
              this.$message('输入正确的城市名称')
            }
          }
        })
      } else {
        // this.drivingRangeOptions = []
        // cb(this.drivingRangeOptions)
      }
    },
    handleSelectCity (item) {
      this.studentBaseInfoVo.destinationPlace = item.name.split('-')[0]
      this.recordDestinationPlace = item.name.split('-')[0]
      this.$refs['studentBaseInfoVo'].validateField(['destinationPlace'])
    },
    changeSearchCity (val) {
      // this.$refs['studentBaseInfoVo'].validateField(['destinationPlace'])
    },
    // 生成图片地址
    generateImgUrl (param) {
      return param ? `/fastdfs-util/api/fastdfs/download/image?filePath=${param}` : defaultPic
    },
    // 初始化函数
    initPage () {
      this.getStudentBaseInfo()
      this.getAllProvinces()
      this.getAllSourcePlace()
      this.getAll()
    },
    prodUrl,
    // 获取所有option
    getAll () {
      dataDictionary()._getAll().then((res) => {
        if (res.status) {
          this.allOption = res.data
        }
      })
    },
    // 获取生源地options
    getAllSourcePlace () {
      dataDictionary()._getAllSourcePlace().then((res) => {
        if (res.status) {
          this.sourcePlaceOptions = res.data
        }
      })
    },
    // 获取学生基信息
    getStudentBaseInfo () {
      student()._getLoginStudentInfo().then((res) => {
        if (res.status) {
          this.studentBasic = res.data.studentBasic
          this.studentContact = res.data.studentContact
          this.studentEducation = res.data.studentEducation

          this.studentParents = R.filter((item) => { return item.type === 0 }, res.data.studentFamilies)
          this.studentrelatives = R.filter((item) => { return item.type === 1 }, res.data.studentFamilies)
          this.studentFriends = R.filter((item) => { return item.type === 2 }, res.data.studentFamilies)
          if (!this.studentParents.length) {
            for (let i = 0; i < 2; i++) {
              let temp = {
                relation: '',
                relationId: null,
                name: '',
                phone: '',
                birthDate: '',
                education: '',
                educationId: '',
                politicsStatus: '',
                politicsStatusId: '',
                workUnit: '',
                duty: '',
                type: 0,
                isEdit: false // 是否在编辑
              }
              this.studentParents.push(temp)
            }
          }

          this.studentBaseInfoVo = R.mergeAll([res.data.studentBasic, res.data.studentContact, res.data.studentEducation])

          this.studentBaseInfoVo.classTeacher = res.data.classTeacher
          this.studentBaseInfoVo.dorm = res.data.dorm
          this.studentBaseInfoVo.dormitoryArea = res.data.dormitoryArea
          this.studentBaseInfoVo.instructorName = res.data.instructorName
          this.studentBaseInfoVo.modifyStatus = res.data.modifyStatus
          this.studentBaseInfoVo.picUrl = res.data.picUrl

          // 处理时间
          if (this.studentBaseInfoVo.birthDate) {
            this.studentBaseInfoVo.birthDate = this.$moment(this.studentBaseInfoVo.birthDate).format('YYYY-MM-DD')
          }
          if (this.studentBaseInfoVo.enterDate) {
            this.studentBaseInfoVo.enterDate = this.$moment(this.studentBaseInfoVo.enterDate).format('YYYY-MM-DD')
          }
          if (this.studentBaseInfoVo.graduateDate) {
            this.studentBaseInfoVo.graduateDate = this.$moment(this.studentBaseInfoVo.graduateDate).format('YYYY-MM')
          }
          // 处理地区级联
          this.studentBaseInfoVo.familyPlaceCode = this.studentBaseInfoVo.familyPlaceCode ? this.studentBaseInfoVo.familyPlaceCode.split(':') : []
          this.studentBaseInfoVo.domicilePlaceCode = this.studentBaseInfoVo.domicilePlaceCode ? this.studentBaseInfoVo.domicilePlaceCode.split(':') : []
          this.studentBaseInfoVo.nativePlaceCode = this.studentBaseInfoVo.nativePlaceCode ? this.studentBaseInfoVo.nativePlaceCode.split(':') : []
          this.studentBaseInfoVo.currentDomicilePlaceCode = this.studentBaseInfoVo.currentDomicilePlaceCode ? this.studentBaseInfoVo.currentDomicilePlaceCode.split(':') : []
          // 计算乘车区间
          if (this.studentBaseInfoVo.departurePlace === null) {
            this.studentBaseInfoVo.departurePlace = '武昌'
          }
          if (this.studentBaseInfoVo.destinationPlace === null) {
            this.studentBaseInfoVo.destinationPlace = ''
          }
          if (this.studentBaseInfoVo.destinationPlace) {
            common()._selectCityByName({name: this.studentBaseInfoVo.destinationPlace}).then(res => {
              if (res.status) {
                if (res.data && res.data.length !== 0) {
                  let temp = res.data.find((item) => {
                    // eslint-disable-next-line no-return-assign
                    return item.name = this.studentBaseInfoVo.destinationPlace
                  })
                  if (temp !== undefined) {
                    this.recordDestinationPlace = this.studentBaseInfoVo.destinationPlace
                  }
                }
              }
            })
          }
          // this.studentBaseInfoVo.rideRange = this.studentBaseInfoVo.destinationPlace // this.studentBaseInfoVo.departurePlace + '-' + this.studentBaseInfoVo.destinationPlace
        }
      })
    },
    // 修改历史
    getCommitHistoryInfo () {
      // 根据auditId查询详情
      student()._findCommitHistoryInfoById(this.$route.query.auditId).then((res) => {
        if (res.status) {
          this.studentBasic = res.data.studentModifyAudit.studentBasicModify
          this.studentContact = res.data.studentModifyAudit.studentContactModify
          this.studentEducation = res.data.studentModifyAudit.studentEducationModify
          this.studentParents = R.filter((item) => { return item.type === 0 }, res.data.studentModifyAudit.studentFamilies)
          this.studentrelatives = R.filter((item) => { return item.type === 1 }, res.data.studentModifyAudit.studentFamilies)
          this.studentFriends = R.filter((item) => { return item.type === 2 }, res.data.studentModifyAudit.studentFamilies)
          if (!this.studentParents.length) {
            for (let i = 0; i < 2; i++) {
              let temp = {
                relation: '',
                relationId: null,
                name: '',
                phone: '',
                birthDate: '',
                education: '',
                educationId: '',
                politicsStatus: '',
                politicsStatusId: '',
                workUnit: '',
                duty: '',
                type: 0,
                isEdit: false // 是否在编辑
              }
              this.studentParents.push(temp)
            }
          }
          this.studentBaseInfoVo = R.mergeAll([res.data.studentModifyAudit.studentBasicModify, res.data.studentModifyAudit.studentContactModify, res.data.studentModifyAudit.studentEducationModify])
          this.studentBaseInfoVo.classTeacher = res.data.classTeacher
          this.studentBaseInfoVo.dorm = res.data.dorm
          this.studentBaseInfoVo.dormitoryArea = res.data.dormitoryArea
          this.studentBaseInfoVo.instructorName = res.data.instructorName
          // this.studentBaseInfoVo.modifyStatus = res.data.modifyStatus
          this.studentBaseInfoVo.picUrl = res.data.picUrl
          // 处理时间
          if (this.studentBaseInfoVo.birthDate) {
            this.studentBaseInfoVo.birthDate = this.$moment(this.studentBaseInfoVo.birthDate).format('YYYY-MM-DD')
          }
          if (this.studentBaseInfoVo.enterDate) {
            this.studentBaseInfoVo.enterDate = this.$moment(this.studentBaseInfoVo.enterDate).format('YYYY-MM-DD')
          }
          if (this.studentBaseInfoVo.graduateDate) {
            this.studentBaseInfoVo.graduateDate = this.$moment(this.studentBaseInfoVo.graduateDate).format('YYYY-MM')
          }
          this.studentBaseInfoVo.familyPlaceCode = this.studentBaseInfoVo.familyPlaceCode ? this.studentBaseInfoVo.familyPlaceCode.split(':') : []
          this.studentBaseInfoVo.domicilePlaceCode = this.studentBaseInfoVo.domicilePlaceCode ? this.studentBaseInfoVo.domicilePlaceCode.split(':') : []
          this.studentBaseInfoVo.nativePlaceCode = this.studentBaseInfoVo.nativePlaceCode ? this.studentBaseInfoVo.nativePlaceCode.split(':') : []
          this.studentBaseInfoVo.currentDomicilePlaceCode = this.studentBaseInfoVo.currentDomicilePlaceCode ? this.studentBaseInfoVo.currentDomicilePlaceCode.split(':') : []

          // 计算乘车区间
          if (this.studentBaseInfoVo.departurePlace === null) {
            this.studentBaseInfoVo.departurePlace = '武昌'
          }
          if (this.studentBaseInfoVo.destinationPlace === null) {
            this.studentBaseInfoVo.destinationPlace = ''
          }
          if (this.studentBaseInfoVo.destinationPlace) {
            common()._selectCityByName({name: this.studentBaseInfoVo.destinationPlace}).then(res => {
              if (res.status) {
                if (res.data && res.data.length !== 0) {
                  let temp = res.data.find((item) => {
                    // eslint-disable-next-line no-return-assign
                    return item.name = this.studentBaseInfoVo.destinationPlace
                  })
                  if (temp !== undefined) {
                    this.recordDestinationPlace = this.studentBaseInfoVo.destinationPlace
                  }
                }
              }
            })
          }
        }
      })
    },
    // 获取所有省份
    getAllProvinces () {
      common()._getProvincesAll().then(res => {
        if (res.status) {
          this.cascadeOptions = res.data
        }
      })
    },
    // 下拉框、级联选择时触发验证
    handleChangeValidate (val, val1) {
      if (val1 === 95) {
        this.basicInfoFormRules.idNumber.push({validator: _checkIdNum, trigger: 'blur'})
        this.$refs['studentBaseInfoVo'].validateField(['idNumber'])
      } else {
        this.basicInfoFormRules.idNumber = [{required: true, message: '请填写身份证号码', trigger: 'blur'}]
        this.$refs['studentBaseInfoVo'].validateField(['idNumber'])
      }
      this.$refs['studentBaseInfoVo'].validateField([val])
    },
    onFamilyPlacechange (val) {
      this.studentBaseInfoVo.familyPlace = this.$refs['cascaderAddr'].currentLabels.join(' ')
      this.handleChangeValidate(val)
    },
    // 返回
    routerGoBack () {
      this.$router.push({
        name: 'student_personalInfo'
      })
    },
    beforeAvatarUpload (file) {
      const isCorrectFormat = /(.jpg|.jpeg|.png)$/i.test(file.name)
      const isLt5M = file.size / 1024 / 1024 < 5

      if (!isCorrectFormat) {
        this.$message.error('上传文件支持 .jpg .jpeg或 .png格式!')
      }
      if (!isLt5M) {
        this.$message.error('上传图片大小不能超过 5MB!')
      }
      return isCorrectFormat && isLt5M
    },
    handleAvatarSuccess (response, file) {
      this.studentBaseInfoVo.lifeHeadUrl = response.data
      this.$refs['studentBaseInfoVo'].validateField(['lifeHeadUrl'])
    },
    // 取消
    resetForm (formName) {
      this.$refs[formName].resetFields()
      this.$router.push({
        name: 'student_personalInfo'
      })
    },
    submitData () {
      let studentBasic = cover(R.merge({}, this.studentBasic), this.studentBaseInfoVo)
      let studentContact = cover(R.merge({}, this.studentContact), this.studentBaseInfoVo)
      let studentEducation = cover(R.merge({}, this.studentEducation), this.studentBaseInfoVo)
      let studentFamilies = [].concat(this.studentParents, this.studentrelatives, this.studentFriends)
      studentFamilies = R.filter((item) => { return (!!item.isEdit) === false || (!!item.isAdd) === false }, studentFamilies)

      // 处理id
      studentBasic.id = this.studentBasic.id
      studentContact.id = this.studentContact.id
      studentEducation.id = this.studentEducation.id
      // 处理级联数组转字符串
      studentBasic.nativePlaceCode = studentBasic.nativePlaceCode.join(':')
      studentBasic.currentDomicilePlaceCode = studentBasic.currentDomicilePlaceCode.join(':')
      studentEducation.domicilePlaceCode = studentEducation.domicilePlaceCode.join(':')
      studentContact.familyPlaceCode = studentContact.familyPlaceCode.join(':')

      studentEducation.graduateDate = this.$moment(studentEducation.graduateDate).format('YYYY-MM-DD')
      // console.log(studentEducation.graduateDate)

      student()._commitUpdateInfo({
        studentBasic,
        studentContact,
        studentEducation,
        studentFamilies
      }).then((res) => {
        if (res.status) {
          this.disable = true
          this.dialogVisible = false
          this.$message({
            message: res.message,
            type: 'success'
          })
          this.$router.push({
            name: 'student_personalInfo'
          })
        }
      })
    },
    // 提交
    submitForm (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.studentParents[0].relationId === null || this.studentParents[1].relationId === null) {
            this.$message.error('父母类关系必选')
            return false
          }

          let studentFriends = R.filter((item) => { return (!!item.isEdit) === false || (!!item.isAdd) === false }, this.studentFriends)
          if (!studentFriends.length) {
            this.$message.error('请至少录入一名其他社会重要联系人类信息')
            return false
          }
          let studentFamilies = [].concat(this.studentParents, this.studentrelatives, this.studentFriends)
          studentFamilies = R.filter((item) => { return (!!item.isEdit) === false || (!!item.isAdd) === false }, studentFamilies)

          if (studentFamilies.length > 10) {
            this.$message.error('家庭联系人类信息不能超过10条')
            return false
          }
          this.dialogVisible = true
        } else {
          return false
        }
      })
    },
    updateRelation (rowData, index, type) {
      rowData.preRow = R.merge({}, rowData)
      if (type === 0) {
        this.$set(this.studentParents[index], 'isEdit', true)
        this.$set(this.studentParents[index], 'isAdd', false)
      } else if (type === 1) {
        this.$set(this.studentrelatives[index], 'isEdit', true)
        this.$set(this.studentrelatives[index], 'isAdd', false)
      } else if (type === 2) {
        this.$set(this.studentFriends[index], 'isEdit', true)
        this.$set(this.studentFriends[index], 'isAdd', false)
      }
    },
    addRelation (type) {
      let isEditArr = []
      if (type === 1) {
        isEditArr = R.filter((item) => { return item.isEdit === true }, this.studentrelatives)
      } else if (type === 2) {
        isEditArr = R.filter((item) => { return item.isEdit === true }, this.studentFriends)
      }

      if (isEditArr.length > 0) {
        this.$message.error('请先保存，在新增')
        return false
      }

      let temp = {
        relation: '',
        relationId: null,
        name: '',
        phone: '',
        birthDate: '',
        education: '',
        educationId: '',
        politicsStatus: '',
        politicsStatusId: '',
        workUnit: '',
        duty: '',
        type: type,
        isEdit: true, // 是否在编辑
        isAdd: true // 是修改还是添加
      }
      if (type === 1) {
        this.studentrelatives.push(temp)
      } else if (type === 2) {
        this.studentFriends.push(temp)
      } else {
        return false
      }
    },
    saveRelation (rowData, type) {
      // 不做表单验证
      if (type === 0 && rowData.relation === '无') {
        rowData.isEdit = false
        return false
      }

      if (rowData.relationId === null || rowData.relationId === undefined || rowData.relationId === '') {
        this.$message.error('请选择关系')
        return false
      }
      if (rowData.name === null || rowData.name === undefined || rowData.name === '') {
        this.$message.error('请填写姓名')
        return false
      } else {
        if (rowData.name.length < 2 || rowData.name.length > 30) {
          this.$message.error('姓名长度在 2 到 30 个字符')
          return false
        }
      }
      if (rowData.phone === null || rowData.phone === undefined || rowData.phone === '') {
        this.$message.error('请填写联系电话')
        return false
      } else {
        if (!/^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[01235678]|18[0-9]|19[189])\d{8}$/.test(rowData.phone)) {
          this.$message.error('联系电话格式不正确')
          return false
        }
      }
      if (rowData.birthDate === null || rowData.birthDate === undefined || rowData.birthDate === '') {
        this.$message.error('请选择出生日期')
        return false
      }
      if (rowData.educationId === null || rowData.educationId === undefined || rowData.educationId === '') {
        this.$message.error('请选择学历')
        return false
      }
      if (rowData.politicsStatusId === null || rowData.politicsStatusId === undefined || rowData.politicsStatusId === '') {
        this.$message.error('请选择政治面貌')
        return false
      }
      if (rowData.workUnit === null || rowData.workUnit === undefined || rowData.workUnit === '') {
        this.$message.error('请填写工作单位')
        return false
      } else {
        if (rowData.workUnit.length < 2 || rowData.workUnit.length > 30) {
          this.$message.error('工作单位长度在 2 到 30 个字符')
          return false
        }
      }
      if (rowData.duty === null || rowData.duty === undefined || rowData.duty === '') {
        this.$message.error('请填写职位')
        return false
      } else {
        if (rowData.duty.length < 2 || rowData.duty.length > 30) {
          this.$message.error('职位长度在 2 到 30 个字符')
          return false
        }
      }
      rowData.isEdit = false
    },
    deleteRelation (scope, type) {
      if (type === 1) {
        this.studentrelatives.splice(scope.$index, 1)
      } else if (type === 2) {
        this.studentFriends.splice(scope.$index, 1)
      } else {
        return false
      }
    },
    cancelRelation (scope, type) {
      if (scope.row.isAdd) {
        if (type === 1) {
          this.studentrelatives.splice(scope.$index, 1)
        } else if (type === 2) {
          this.studentFriends.splice(scope.$index, 1)
        } else {
          return false
        }
      } else {
        scope.row.relation = scope.row.preRow.relation
        scope.row.relationId = scope.row.preRow.relationId
        scope.row.name = scope.row.preRow.name
        scope.row.phone = scope.row.preRow.phone
        scope.row.birthDate = scope.row.preRow.birthDate
        scope.row.education = scope.row.preRow.education
        scope.row.educationId = scope.row.preRow.educationId
        scope.row.politicsStatus = scope.row.preRow.politicsStatus
        scope.row.politicsStatusId = scope.row.preRow.politicsStatusId
        scope.row.workUnit = scope.row.preRow.workUnit
        scope.row.duty = scope.row.preRow.duty
        scope.row.type = scope.row.preRow.type
        scope.row.isEdit = false
      }
    },
    handleChange (rowData, type) {
      if (type === '父母' || type === '直系亲属' || type === '社会联系人') {
        rowData.relation = R.find(R.propEq('id', rowData.relationId))(this.allOption[type]).name
        if (type === '父母' && rowData.relation === '无') {
          rowData.name = ''
          rowData.phone = ''
          rowData.birthDate = ''
          rowData.education = ''
          rowData.educationId = ''
          rowData.politicsStatus = ''
          rowData.politicsStatusId = ''
          rowData.workUnit = ''
          rowData.duty = ''
        }
      } else if (type === '学历') {
        rowData.education = R.find(R.propEq('id', rowData.educationId))(this.allOption[type]).name
      } else if (type === '政治面貌') {
        rowData.politicsStatus = R.find(R.propEq('id', rowData.politicsStatusId))(this.allOption[type]).name
      }
    },
    getBirthdayFromIdCard: function (idCard) {
      var birthday = ''
      if (idCard !== null && idCard !== '') {
        if (idCard.length === 15) {
          birthday = '19' + idCard.substr(6, 6)
        } else if (idCard.length === 18) {
          birthday = idCard.substr(6, 8)
        }

        birthday = birthday.replace(/(.{4})(.{2})/, '$1-$2-')
      }

      return birthday
    },
    updateBirthDate () {
      if (checkCode(this.studentBaseInfoVo.idNumber)) {
        this.studentBaseInfoVo.birthDate = this.getBirthdayFromIdCard(this.studentBaseInfoVo.idNumber)
      }
    }
  }
}
</script>
<style lang="less" scoped>
.red {
  color: red;
}
.avatar-uploader img {
  width: 130px;
  height: 160px;
}
</style>
